//
//  NBADViewController.m
//  qiFenQi
//
//  Created by 戒了。 on 16/4/14.
//  Copyright © 2016年 xiaomage. All rights reserved.
//

#import "NBADViewController.h"
#import "NBADItem.h"
#import <AFNetworking.h>
#import "NBTabBarController.h"


@interface NBADViewController ()
@property (weak, nonatomic) IBOutlet UIImageView *launchImageView;
@property (weak, nonatomic) IBOutlet UIButton *jumpBtn;
@property (weak, nonatomic) IBOutlet UIView *adView;
@property (nonatomic, weak) UIImageView *imageView;
@property (nonatomic, weak) NSTimer *timer;
@end


/*
 业务逻辑:
 1.点击广告图片 跳转到广告界面 用safari打开
 2.广告界面倒计时
 3.点击跳过,直接进入到主框架界面
 */
@implementation NBADViewController

- (UIImageView *)imageView
{
    if (_imageView == nil) {
        UIImageView *imageView = [[UIImageView alloc] init];
        _imageView = imageView;
        [self.adView addSubview:imageView];
    
        imageView.userInteractionEnabled = YES;
        
        //添加点按手势
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap)];
        [imageView addGestureRecognizer:tap];
    }
    return _imageView;
}

#pragma mark - 点击跳转按钮

- (IBAction)clickJump:(id)sender {
    //钮跳到主框架,更改窗口的跟控制器
    [UIApplication sharedApplication].keyWindow.rootViewController = [[NBTabBarController alloc] init];
    
    //销毁定时器
    [_timer invalidate];
}

#pragma mark - 点击广告图片
- (void)tap
{
    //跳转广告界面
    
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    // 设置启动图片 -> 根据不同屏幕 加载不同图片 (屏幕适配)
    [self setupLaunchImage];

    //加载广告数据
    [self loadData];
    
    //创建定时器
    _timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(timeChange) userInfo:nil repeats:YES];
}

- (void)timeChange
{
    static int i = 3;
    if (i <= 0) {//跳转界面
        [self clickJump:nil];
    }
    i --;
    
    //设置按钮标题
    NSString *str = [NSString stringWithFormat:@"跳转 (%d)",i];
    [self.jumpBtn setTitle:str forState:UIControlStateNormal];
}

- (void)setupLaunchImage
{
    // 根据不同屏幕高度 加载不同图片
    UIImage *image = nil;
    if (iphone6P) {
        image = [UIImage imageNamed:@"LaunchImage-800-Portrait"];
    } else if (iphone6) {
        image = [UIImage imageNamed:@"LaunchImage-800"];
    } else if (iphone5) {
        image = [UIImage imageNamed:@"LaunchImage-700"];
    }
    _launchImageView.image = image;
}

//加载广告数据
- (void)loadData
{
    //创建会话管理者
    
    //创建请求参数
    
    //发送请求
    
    
}

@end
